home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML Instance.sea / XML Instance / Required / ccs_util.jar / test / textui / TextTestResult.class (.txt) < prev   
Encoding:
Java Class File  |  1999-12-09  |  3.1 KB  |  88 lines

  1. package test.textui;
  2.  
  3. import java.util.Enumeration;
  4. import test.framework.Test;
  5. import test.framework.TestFailure;
  6. import test.framework.TestResult;
  7.  
  8. class TextTestResult extends TestResult {
  9.    public synchronized void addError(Test test, Throwable t) {
  10.       super.addError(test, t);
  11.       System.out.println("E");
  12.    }
  13.  
  14.    public synchronized void addFailure(Test test, Throwable t) {
  15.       super.addFailure(test, t);
  16.       System.out.print("F");
  17.    }
  18.  
  19.    public synchronized void startTest(Test test) {
  20.       super.startTest(test);
  21.       System.out.print(".");
  22.    }
  23.  
  24.    public void printErrors() {
  25.       if (((TestResult)this).testErrors() != 0) {
  26.          if (((TestResult)this).testErrors() == 1) {
  27.             System.out.println("There was " + ((TestResult)this).testErrors() + " error:");
  28.          } else {
  29.             System.out.println("There were " + ((TestResult)this).testErrors() + " errors:");
  30.          }
  31.  
  32.          int i = 1;
  33.  
  34.          for(Enumeration e = ((TestResult)this).errors(); e.hasMoreElements(); ++i) {
  35.             TestFailure failure = (TestFailure)e.nextElement();
  36.             System.out.println(i + ") " + failure.failedTest());
  37.             failure.thrownException().printStackTrace();
  38.          }
  39.       }
  40.  
  41.    }
  42.  
  43.    public void printFailures() {
  44.       if (((TestResult)this).testFailures() != 0) {
  45.          if (((TestResult)this).testFailures() == 1) {
  46.             System.out.println("There was " + ((TestResult)this).testFailures() + " failure:");
  47.          } else {
  48.             System.out.println("There were " + ((TestResult)this).testFailures() + " failures:");
  49.          }
  50.  
  51.          int i = 1;
  52.  
  53.          for(Enumeration e = ((TestResult)this).failures(); e.hasMoreElements(); ++i) {
  54.             TestFailure failure = (TestFailure)e.nextElement();
  55.             System.out.print(i + ") " + failure.failedTest());
  56.             Throwable t = failure.thrownException();
  57.             if (t.getMessage() != null) {
  58.                System.out.println(" \"" + t.getMessage() + "\"");
  59.             } else {
  60.                System.out.println();
  61.                failure.thrownException().printStackTrace();
  62.             }
  63.          }
  64.       }
  65.  
  66.    }
  67.  
  68.    public synchronized void print() {
  69.       this.printHeader();
  70.       this.printErrors();
  71.       this.printFailures();
  72.    }
  73.  
  74.    public void printHeader() {
  75.       if (((TestResult)this).wasSuccessful()) {
  76.          System.out.println();
  77.          System.out.print("OK");
  78.          System.out.println(" (" + ((TestResult)this).runTests() + " tests)");
  79.       } else {
  80.          System.out.println();
  81.          System.out.println("!!!FAILURES!!!");
  82.          System.out.println("Test Results:");
  83.          System.out.println("Run: " + ((TestResult)this).runTests() + " Failures: " + ((TestResult)this).testFailures() + " Errors: " + ((TestResult)this).testErrors());
  84.       }
  85.  
  86.    }
  87. }
  88.